home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / frasr182.zip / FRACSUBR.C < prev    next >
C/C++ Source or Header  |  1993-06-07  |  32KB  |  995 lines

  1. /*
  2. FRACSUBR.C contains subroutines which belong primarily to CALCFRAC.C and
  3. FRACTALS.C, i.e. which are non-fractal-specific fractal engine subroutines.
  4. */
  5.  
  6. #include <stdio.h>
  7. #ifndef XFRACT
  8. #include <stdarg.h>
  9. #else
  10. #include <varargs.h>
  11. #endif
  12. #include <float.h>
  13. #include <sys/types.h>
  14. #include <sys/timeb.h>
  15. #include <stdlib.h>
  16. #include "fractint.h"
  17. #include "fractype.h"
  18. #include "mpmath.h"
  19. #include "prototyp.h"
  20.  
  21. /* routines in this module    */
  22.  
  23. static long   _fastcall fudgetolong(double d);
  24. static double _fastcall fudgetodouble(long l);
  25. static void   _fastcall adjust_to_limits(double);
  26. static void   _fastcall smallest_add(double *);
  27. static int    _fastcall ratio_bad(double,double);
  28. static void   _fastcall plotdorbit(double,double,int);
  29. static int    _fastcall combine_worklist(void);
  30.  
  31.  
  32. extern int    calc_status;        /* status of calculations */
  33. extern char far *resume_info;        /* pointer to resume info if allocated */
  34.        int    resume_len;        /* length of resume info */
  35. static int    resume_offset;        /* offset in resume info gets */
  36. extern double plotmx1,plotmx2,plotmy1,plotmy2; /* real->screen conversion */
  37. extern int    orbit_ptr;        /* pointer into save_orbit array */
  38. extern int orbit_delay;         /* orbit delay value */
  39. extern int far *save_orbit;        /* array to save orbit values */
  40. extern int    orbit_color;        /* XOR color */
  41. extern int    num_worklist;        /* resume worklist for standard engine */
  42. extern int    fractype;         /* fractal type */
  43. extern char   stdcalcmode;        /* '1', '2', 'g', 'b'       */
  44. extern char   floatflag;        /* floating-point fractals? */
  45. extern int    integerfractal;        /* TRUE if fractal uses integer math */
  46. extern struct workliststuff worklist[MAXCALCWORK];
  47. extern int    sxdots,sydots;        /* # of dots on the physical screen    */
  48. extern int    sxoffs,syoffs;        /* physical top left of logical screen */
  49. extern int    xdots, ydots;        /* # of dots on the logical screen     */
  50. extern int    colors;            /* maximum colors available */
  51. extern long   fudge;            /* fudge factor (2**n) */
  52. extern int    bitshift;         /* bit shift for fudge */
  53. extern int    inside;            /* inside color: 1=blue     */
  54. extern int    outside;            /* outside color    */
  55. extern double xxmin,xxmax,yymin,yymax,xx3rd,yy3rd; /* corners */
  56. extern long   xmin, xmax, ymin, ymax, x3rd, y3rd;  /* integer equivs */
  57. extern int    maxit;            /* try this many iterations */
  58. extern int    attractors;        /* number of finite attractors    */
  59. extern _CMPLX  attr[];        /* finite attractor vals (f.p)    */
  60. extern _LCMPLX lattr[];     /* finite attractor vals (int)    */
  61. extern int    attrperiod[];         /* finite attractor period    */
  62. extern _CMPLX  old,new;
  63. extern _LCMPLX lold,lnew;
  64. extern double tempsqrx,tempsqry;
  65. extern long   ltempsqrx,ltempsqry;
  66. extern int    xxstart,xxstop;        /* these are same as worklist, */
  67. extern int    yystart,yystop,yybegin;    /* declared as separate items  */
  68. extern int    periodicitycheck;
  69. extern int    basin;
  70. extern int    finattract;
  71. extern int    pixelpi;            /* value of pi in pixels */
  72. extern double closenuff;
  73. extern long   lclosenuff;
  74. extern int    ixstart, ixstop, iystart, iystop;
  75. extern int    color;
  76. extern int    decomp[];
  77. extern double potparam[3];        /* three potential parameters*/
  78. extern int    distest;            /* non-zero if distance estimator */
  79. extern double param[];          /* parameters */
  80. extern int    invert;            /* non-zero if inversion active */
  81. extern int    biomorph,usr_biomorph;
  82. extern int    debugflag; /* internal use only - you didn't see this */
  83. extern long   creal, cimag;        /* for calcmand */
  84. extern long   delx, dely;        /* screen pixel increments  */
  85. extern long   delx2, dely2;        /* screen pixel increments  */
  86. extern double delxx, delyy;        /* screen pixel increments  */
  87. extern double delxx2, delyy2;        /* screen pixel increments  */
  88. extern long   delmin;            /* for calcfrac/calcmand    */
  89. extern double ddelmin;            /* same as a double        */
  90. extern int    potflag;            /* continuous potential flag */
  91. extern int    bailout;
  92. extern double rqlim;
  93. extern double  dxsize, dysize;        /* xdots-1, ydots-1        */
  94. extern int soundflag;
  95. extern int basehertz;
  96.  
  97. extern long   far *lx0, far *ly0;    /* x, y grid            */
  98. extern long   far *lx1, far *ly1;    /* adjustment for rotate    */
  99. /* note that lx1 & ly1 values can overflow into sign bit; since     */
  100. /* they're used only to add to lx0/ly0, 2s comp straightens it out  */
  101. extern double far *dx0, far *dy0;    /* floating pt equivs */
  102. extern double far *dx1, far *dy1;
  103.  
  104. extern char   usr_floatflag;
  105. extern char   usr_stdcalcmode;
  106. extern int    usr_periodicitycheck;
  107. extern int    usr_distest;
  108. extern double zwidth;
  109.  
  110. extern int neworbittype;
  111.  
  112. #define FUDGEFACTOR    29    /* fudge all values up by 2**this */
  113. #define FUDGEFACTOR2    24    /* (or maybe this)          */
  114.  
  115.  
  116. void calcfracinit() /* initialize a *pile* of stuff for fractal calculation */
  117. {
  118.    int i;
  119.    double ftemp;
  120.  
  121.    floatflag = usr_floatflag;
  122.    if (calc_status == 2) /* on resume, ensure floatflag correct */
  123.       if (curfractalspecific->isinteger)
  124.      floatflag = 0;
  125.       else
  126.      floatflag = 1;
  127.    /* if floating pt only, set floatflag for TAB screen */
  128.    if (!curfractalspecific->isinteger && curfractalspecific->tofloat == NOFRACTAL)
  129.       floatflag = 1;
  130.  
  131. init_restart:
  132.  
  133.    /* the following variables may be forced to a different setting due to
  134.       calc routine constraints;  usr_xxx is what the user last said is wanted,
  135.       xxx is what we actually do in the current situation */
  136.    stdcalcmode        = usr_stdcalcmode;
  137.    periodicitycheck = usr_periodicitycheck;
  138.    distest        = usr_distest;
  139.    biomorph        = usr_biomorph;
  140.  
  141.    potflag = 0;
  142.    if (potparam[0] != 0.0
  143.      && colors >= 64
  144.      && (curfractalspecific->calctype == StandardFractal
  145.      || curfractalspecific->calctype == calcmand
  146.      || curfractalspecific->calctype == calcmandfp)) {
  147.       potflag = 1;
  148.       distest = 0;    /* can't do distest too */
  149.       }
  150.  
  151.    if (distest)
  152.       floatflag = 1;  /* force floating point for dist est */
  153.  
  154.    if (floatflag) { /* ensure type matches floatflag */
  155.       if (curfractalspecific->isinteger != 0
  156.     && curfractalspecific->tofloat != NOFRACTAL)
  157.      fractype = curfractalspecific->tofloat;
  158.       }
  159.    else {
  160.       if (curfractalspecific->isinteger == 0
  161.     && curfractalspecific->tofloat != NOFRACTAL)
  162.      fractype = curfractalspecific->tofloat;
  163.       }
  164.    /* match Julibrot with integer mode of orbit */   
  165.    if(fractype == JULIBROTFP && fractalspecific[neworbittype].isinteger)
  166.    {
  167.       int i;
  168.       if((i=fractalspecific[neworbittype].tofloat) != NOFRACTAL)
  169.          neworbittype = i;
  170.       else
  171.          fractype = JULIBROT;   
  172.    }
  173.    else if(fractype == JULIBROT && fractalspecific[neworbittype].isinteger==0)
  174.    {
  175.       int i;
  176.       if((i=fractalspecific[neworbittype].tofloat) != NOFRACTAL)
  177.          neworbittype = i;
  178.       else
  179.          fractype = JULIBROTFP;   
  180.    }
  181.       
  182.    curfractalspecific = &fractalspecific[fractype];
  183.  
  184.    integerfractal = curfractalspecific->isinteger;
  185.  
  186. /*   if (fractype == JULIBROT)
  187.       rqlim = 4;
  188.    else */ if (potflag && potparam[2] != 0.0)
  189.       rqlim = potparam[2];
  190. /* else if (decomp[0] > 0 && decomp[1] > 0)
  191.       rqlim = (double)decomp[1]; */
  192.    else if (bailout) /* user input bailout */
  193.       rqlim = bailout;
  194.    else if (biomorph != -1) /* biomorph benefits from larger bailout */
  195.       rqlim = 100;
  196.    else
  197.       rqlim = curfractalspecific->orbit_bailout;
  198.    if (integerfractal) /* the bailout limit mustn't be too high here */
  199.       if (rqlim > 127.0) rqlim = 127.0;
  200.  
  201.    if ((curfractalspecific->flags&NOROTATE) != 0) {
  202.       /* ensure min<max and unrotated rectangle */
  203.       if (xxmin > xxmax) { ftemp = xxmax; xxmax = xxmin; xxmin = ftemp; }
  204.       if (yymin > yymax) { ftemp = yymax; yymax = yymin; yymin = ftemp; }
  205.       xx3rd = xxmin; yy3rd = yymin;
  206.       }
  207.  
  208.    /* set up bitshift for integer math */
  209.    bitshift = FUDGEFACTOR2; /* by default, the smaller shift */
  210.    if (integerfractal > 1)  /* use specific override from table */
  211.       bitshift = integerfractal;
  212.    if (integerfractal == 0) /* float? */
  213.       if ((i = curfr